import { createSlice } from '@reduxjs/toolkit'
import { v4 as uuidv4 } from 'uuid'

const codeSlice = createSlice({
  name: 'create',
  initialState: {
    codeAll: [],
    codeChange: false,
    languageChange: false,
    id: uuidv4(),
    exit: false,
    ip: 'localhost'
  },
  reducers: {
    setCodeAll(state, action) {
      state.codeAll = action.payload
    },
    setCodeChange(state, action) {
      state.codeChange = action.payload
    },
    setLanguageChange(state, action) {
      state.languageChange = action.payload
    },
    setID(state, action) {
      state.id = action.payload
    },
    setExit(state, action) {
      state.exit = action.payload
    },
    setIP(state, action) {
      state.ip = action.payload
    },
    resetStateCodeall(state) {
      state.codeAll = []
      state.codeChange = false
      state.languageChange = false
      state.exit = false
      state.id = uuidv4()
    }
  }
})

export const {
  setCodeAll,
  setCodeChange,
  setLanguageChange,
  setID,
  resetStateCodeall,
  setExit,
  setIP
} = codeSlice.actions

export default codeSlice.reducer
